﻿#region Using References

using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using Beaker.OpenCube.Textures;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Beaker.OpenCube.Specs.Textures
{
	[ExcludeFromCodeCoverage]
	[TestClass]
	public class TextureSpecs
	{
		[TestMethod]
		public void TextureConstructorShouldThrowWhenNoImageProvided()
		{
			// act
			Action create = () => new Texture( null );

			// assert
			create.ShouldThrow<ArgumentNullException>( "Should throw when no image is provided" );
		}

		[TestMethod]
		public void TextureConstructorShouldThrowWhenHorizontalResolutionIsNotPowerOfTwo()
		{
			// arrange
			var image = new Bitmap( 63, 64 );

			// act
			Action create = () => new Texture( image );

			// assert
			create.ShouldThrow<ArgumentException>( "Should throw when horizontal resolution is not a power of two" );
		}

		[TestMethod]
		public void TextureConstructorRequiresHorizontalResolutionThatIsPowerOfTwo()
		{
			// arrange
			var image = new Bitmap( 64, 64 );

			// act
			var texture = new Texture( image );
		}

		[TestMethod]
		public void TextureConstructorHeightShouldBeMultipleOfTextureWidth()
		{
			// arrange
			var image = new Bitmap( 16, 32 );

			// act
			var texture = new Texture( image );
		}

		[TestMethod]
		public void TextureConstructorShouldThrowWhenHeightNotMultipleOfTextureWidth()
		{
			// arrange
			var image = new Bitmap( 16, 20 );

			// act
			Action create = () => new Texture( image );

			// assert
			create.ShouldThrow<ArgumentException>();
		}

		[TestMethod]
		public void FrameImageCountIsBasedOnWidthVsHeight()
		{
			// arrange
			var image = new Bitmap( 16, 64 );

			// act
			var texture = new Texture( image );

			// assert
			texture.ImageCount.Should().Be( 4 );
		}

		[TestMethod]
		public void WhenNoFrameInfoGivenDefaultsToSingleFrameAtIndex0()
		{
			// arrange
			var image = new Bitmap( 16, 16 );

			// act
			var texture = new Texture( image );

			// assert
			texture.FrameCount.Should().Be( 1 );
			texture.FrameInformation.Should().Equal( new FrameInfo( 0 ) );
		}

		[TestMethod]
		public void WhenFrameInfoGivenTotalFramesShouldBeSumOfFrameInfo()
		{
			// arrange
			var image = new Bitmap( 16, 32 );

			// act
			var texture = new Texture( image, new[] { new FrameInfo( 1, 2 ), new FrameInfo( 0, 4 ), } );

			// assert
			texture.FrameCount.Should().Be( 6 );
		}
	}
}